/**
 * 
 */
package info.niwota.webime.http;

/**
 * @author qiangli
 *
 */
public class Server {

	private HttpServer httpServer;

	private ServerContext ctx;
	
	public void init(ServerContext ctx) {
		this.ctx = ctx;
	}
	
	public boolean isRunning() {
		boolean http = (httpServer != null && httpServer.isRunning());
		return http;
	}

	public void startServer() throws Exception {
		httpServer = new HttpServer();
		httpServer.init(ctx);
		httpServer.startup();

	}

	public void stopServer() {
		if (httpServer != null) {
			try {
				httpServer.shutdown();
			} catch (Exception e) {
				e.printStackTrace();
			} finally {
				httpServer = null;
			}
		}
	}

	
	public static void main(String[] args) {
		Server s = new Server();
		try {
			ServerContext ctx = new ServerContext();
			ctx.port = 1080;
			s.init(ctx);
			s.startServer();
		} catch (Exception e) {
			e.printStackTrace();
		}
		try {
			Thread.sleep(Long.MAX_VALUE);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
}
